package top.lingkang.potatoserver.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import top.lingkang.security.CheckAuth;
import top.lingkang.security.FinalHttpSecurity;
import top.lingkang.security.impl.DefaultCheckAuth;
import top.lingkang.session.impl.FinalRedisSessionManager;

import java.util.HashMap;

/**
 * @author lingkang
 * @date 2021/9/18 23:30
 * @description
 */
@Configuration
public class FinalSecurityConfig {

    @Autowired
    private RedisTemplate redisTemplate;

    @Bean
    public FinalRedisSessionManager finalRedisSessionManager() {
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        return new FinalRedisSessionManager(redisTemplate);
    }

    @Bean
    public FinalHttpSecurity finalHttpSecurity() {
        FinalHttpSecurity security = new FinalHttpSecurity();
        HashMap<String, CheckAuth> map = new HashMap<String, CheckAuth>();
        map.put("/*", new DefaultCheckAuth().checkLogin());
        security.setCheckAuthHashMap(map);
        security.setExcludePath("/account/**", "/assets/**");
        return security;
    }

}
